package view.invoice;

import java.util.Observable;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import controller.invoice.InvoiceControl;

public class InvoiceAddPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private JButton btnInvaddAdd;
	private JButton btnInvaddAddnew;
	private JButton btnInvaddCancel;
	private JButton btnInvaddCheck;
	private JComboBox<String> cbbInvadd;
	private JScrollPane jScrollPane1;
	private JLabel lblInvaddCustomerID;
	private JLabel lblInvaddDate;
	private JLabel lblInvaddDate2;
	private JLabel lblInvCustomerName;
	private JLabel lblInvaddProductid;
	private JLabel lblInvaddQuantity;
	private JLabel lblInvaddTotal;
	private JPanel pnInvaddInformation;
	private JPanel pnInvaddInvoicedetail;
	private JTable tblInvaddInvoicedetail;
	private JTextField txtInvCustomerId;
	private JTextField txtInvaddInvoiceid;
	private JTextField txtInvaddQuantity;
	private JTextField txtInvaddPrice;
	
	private InvoiceControl controller;
	
	private Observable obs;
	
	public void setObs(Observable obs){
		this.obs = obs;
	}
	
	public Observable getObs(){
		return this.obs;
	}
	
	public InvoiceControl getController(){
		return this.controller;
	}

	public InvoiceAddPanel() {
		initComponents();
		events();
	}

	public JButton getBtnInvaddAdd() {
		return btnInvaddAdd;
	}

	public void setBtnInvaddAdd(JButton btnInvaddAdd) {
		this.btnInvaddAdd = btnInvaddAdd;
	}

	public JButton getBtnInvaddAddnew() {
		return btnInvaddAddnew;
	}

	public void setBtnInvaddAddnew(JButton btnInvaddAddnew) {
		this.btnInvaddAddnew = btnInvaddAddnew;
	}

	public JButton getBtnInvaddCancel() {
		return btnInvaddCancel;
	}

	public void setBtnInvaddCancel(JButton btnInvaddCancel) {
		this.btnInvaddCancel = btnInvaddCancel;
	}

	public JButton getBtnInvaddCheck() {
		return btnInvaddCheck;
	}

	public void setBtnInvaddCheck(JButton btnInvaddCheck) {
		this.btnInvaddCheck = btnInvaddCheck;
	}

	public JComboBox<String> getCbbInvadd1() {
		return cbbInvadd;
	}

	public void setCbbInvadd(JComboBox<String> cbbInvadd) {
		this.cbbInvadd = cbbInvadd;
	}

	public JScrollPane getjScrollPane1() {
		return jScrollPane1;
	}

	public void setjScrollPane1(JScrollPane jScrollPane1) {
		this.jScrollPane1 = jScrollPane1;
	}

	public JLabel getLblInvaddCustomerID() {
		return lblInvaddCustomerID;
	}

	public void setLblInvaddCustomerID(JLabel lblInvaddCustomerID) {
		this.lblInvaddCustomerID = lblInvaddCustomerID;
	}

	public JLabel getLblInvaddDate() {
		return lblInvaddDate;
	}

	public void setLblInvaddDate(JLabel lblInvaddDate) {
		this.lblInvaddDate = lblInvaddDate;
	}

	public JLabel getLblInvaddDate2() {
		return lblInvaddDate2;
	}

	public void setLblInvaddDate2(JLabel lblInvaddDate2) {
		this.lblInvaddDate2 = lblInvaddDate2;
	}

	public JLabel getLblInvaddInvoiceid() {
		return lblInvCustomerName;
	}

	public void setLblInvaddInvoiceid(JLabel lblInvaddInvoiceid) {
		this.lblInvCustomerName = lblInvaddInvoiceid;
	}

	public JLabel getLblInvaddProductid() {
		return lblInvaddProductid;
	}

	public void setLblInvaddProductid(JLabel lblInvaddProductid) {
		this.lblInvaddProductid = lblInvaddProductid;
	}

	public JLabel getLblInvaddQuantity() {
		return lblInvaddQuantity;
	}

	public void setLblInvaddQuantity(JLabel lblInvaddQuantity) {
		this.lblInvaddQuantity = lblInvaddQuantity;
	}

	public JLabel getLblInvaddTotal() {
		return lblInvaddTotal;
	}

	public void setLblInvaddTotal(JLabel lblInvaddTotal) {
		this.lblInvaddTotal = lblInvaddTotal;
	}

	public JPanel getPnInvaddInformation() {
		return pnInvaddInformation;
	}

	public void setPnInvaddInformation(JPanel pnInvaddInformation) {
		this.pnInvaddInformation = pnInvaddInformation;
	}

	public JPanel getPnInvaddInvoicedetail() {
		return pnInvaddInvoicedetail;
	}

	public void setPnInvaddInvoicedetail(JPanel pnInvaddInvoicedetail) {
		this.pnInvaddInvoicedetail = pnInvaddInvoicedetail;
	}

	public JTable getTblInvaddInvoicedetail() {
		return tblInvaddInvoicedetail;
	}

	public void setTblInvaddInvoicedetail(JTable tblInvaddInvoicedetail) {
		this.tblInvaddInvoicedetail = tblInvaddInvoicedetail;
	}

	public JTextField getTxtInvaddCustomerID() {
		return txtInvCustomerId;
	}

	public void setTxtInvaddCustomerID(JTextField txtInvaddCustomerID) {
		this.txtInvCustomerId = txtInvaddCustomerID;
	}

	public JTextField getTxtInvaddInvoiceid() {
		return txtInvaddInvoiceid;
	}

	public void setTxtInvaddInvoiceid(JTextField txtInvaddInvoiceid) {
		this.txtInvaddInvoiceid = txtInvaddInvoiceid;
	}

	public JTextField getTxtInvaddQuantity() {
		return txtInvaddQuantity;
	}

	public void setTxtInvaddQuantity(JTextField txtInvaddQuantity) {
		this.txtInvaddQuantity = txtInvaddQuantity;
	}

	public JTextField getTxtInvaddTotal() {
		return txtInvaddPrice;
	}

	public void setTxtInvaddTotal(JTextField txtInvaddTotal) {
		this.txtInvaddPrice = txtInvaddTotal;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	public JLabel getLblInvCustomerName() {
		return lblInvCustomerName;
	}

	public void setLblInvCustomerName(JLabel lblInvCustomerName) {
		this.lblInvCustomerName = lblInvCustomerName;
	}

	public JTextField getTxtInvCustomerName() {
		return txtInvCustomerId;
	}

	public void setTxtInvCustomerName(JTextField txtInvCustomerName) {
		this.txtInvCustomerId = txtInvCustomerName;
	}

	public JTextField getTxtInvaddPrice() {
		return txtInvaddPrice;
	}

	public void setTxtInvaddPrice(JTextField txtInvaddPrice) {
		this.txtInvaddPrice = txtInvaddPrice;
	}

	private void initComponents() {
		
		pnInvaddInformation = new JPanel();
		lblInvCustomerName = new JLabel();
		txtInvaddInvoiceid = new JTextField();
		lblInvaddDate = new JLabel();
		lblInvaddDate2 = new JLabel();
		lblInvaddCustomerID = new JLabel();
		txtInvCustomerId = new JTextField();
		btnInvaddCheck = new JButton();
		pnInvaddInvoicedetail = new JPanel();
		lblInvaddProductid = new JLabel();
		lblInvaddQuantity = new JLabel();
		txtInvaddQuantity = new JTextField();
		lblInvaddTotal = new JLabel();
		txtInvaddPrice = new JTextField();
		btnInvaddAddnew = new JButton();
		jScrollPane1 = new JScrollPane();
		tblInvaddInvoicedetail = new JTable();
		cbbInvadd = new JComboBox<String>();
		btnInvaddAdd = new JButton();
		btnInvaddCancel = new JButton();
		controller = new InvoiceControl(this);
		
		pnInvaddInformation.setBackground(new java.awt.Color(255, 255, 255));
		pnInvaddInformation.setBorder(BorderFactory.createTitledBorder(null,
				"Information", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1,
						12), java.awt.Color.blue));

		lblInvCustomerName.setFont(new java.awt.Font("Calibri", 0, 12));
		lblInvCustomerName.setText("Customer Name:");

		txtInvaddInvoiceid
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						txt_invadd_invoiceidActionPerformed(evt);
					}
				});
//		txtInvaddInvoiceid.setEnabled(false);
		lblInvaddDate.setFont(new java.awt.Font("Calibri", 0, 12));
		lblInvaddDate.setText("Date:");

		lblInvaddDate2.setFont(new java.awt.Font("Calibri", 0, 12));
		lblInvaddDate2.setText("22/12/2014");

		lblInvaddCustomerID.setFont(new java.awt.Font("Calibri", 0, 12));
		lblInvaddCustomerID.setText("Customer ID:");

		btnInvaddCheck.setIcon(new ImageIcon("icon/check.png"));
		btnInvaddCheck.setText("Check");
		btnInvaddCheck.addActionListener(controller);
		btnInvaddCheck.setVisible(false);

		GroupLayout pn_invadd_informationLayout = new GroupLayout(pnInvaddInformation);
		pnInvaddInformation.setLayout(pn_invadd_informationLayout);
        pn_invadd_informationLayout.setHorizontalGroup(
            pn_invadd_informationLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pn_invadd_informationLayout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addComponent(lblInvaddCustomerID)
                .addGap(18, 18, 18)
                .addComponent(txtInvCustomerId, GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(lblInvCustomerName)
                .addGap(18, 18, 18)
                .addComponent(txtInvaddInvoiceid, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pn_invadd_informationLayout.setVerticalGroup(
            pn_invadd_informationLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pn_invadd_informationLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pn_invadd_informationLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblInvaddCustomerID)
                    .addComponent(txtInvCustomerId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblInvCustomerName)
                    .addComponent(txtInvaddInvoiceid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

		pnInvaddInvoicedetail.setBackground(new java.awt.Color(255, 255, 255));
		pnInvaddInvoicedetail.setBorder(BorderFactory.createTitledBorder(null,
				"Invoice detail", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1,
						12), java.awt.Color.blue));

		lblInvaddProductid.setFont(new java.awt.Font("Calibri", 0, 12));
		lblInvaddProductid.setText("Product ID:");

		lblInvaddQuantity.setFont(new java.awt.Font("Calibri", 0, 12));
		lblInvaddQuantity.setText("Quantity:");

		lblInvaddTotal.setFont(new java.awt.Font("Calibri", 0, 12));
		lblInvaddTotal.setText("Price:");
		
		btnInvaddAddnew.addActionListener(controller);
		btnInvaddAddnew.setIcon(new ImageIcon("icon/add.png"));
		btnInvaddAddnew.setText("Add new");

		tblInvaddInvoicedetail.setModel(new DefaultTableModel(new Object[][] {
				{ null, null, null, null }, { null, null, null, null },
				{ null, null, null, null }, { null, null, null, null },
				{ null, null, null, null }, { null, null, null, null },
				{ null, null, null, null }, { null, null, null, null },
				{ null, null, null, null }, { null, null, null, null },
				{ null, null, null, null }, { null, null, null, null },
				{ null, null, null, null }, { null, null, null, null } },
				new String[] { "Product ID", "Product name", "Quantity",
						"Price" }));
		jScrollPane1.setViewportView(tblInvaddInvoicedetail);

	
		
		GroupLayout pn_invadd_invoicedetailLayout = new GroupLayout(
				pnInvaddInvoicedetail);
		pnInvaddInvoicedetail.setLayout(pn_invadd_invoicedetailLayout);
		pn_invadd_invoicedetailLayout
				.setHorizontalGroup(pn_invadd_invoicedetailLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_invadd_invoicedetailLayout
										.createSequentialGroup()
										.addGap(64, 64, 64)
										.addComponent(lblInvaddProductid)
										.addGap(18, 18, 18)
										.addComponent(cbbInvadd,
												GroupLayout.PREFERRED_SIZE,
												128, GroupLayout.PREFERRED_SIZE)
										.addGap(50, 50, 50)
										.addComponent(lblInvaddQuantity)
										.addGap(18, 18, 18)
										.addComponent(txtInvaddQuantity,
												GroupLayout.PREFERRED_SIZE,
												114, GroupLayout.PREFERRED_SIZE)
										.addGap(69, 69, 69)
										.addComponent(lblInvaddTotal)
										.addGap(18, 18, 18)
										.addComponent(txtInvaddPrice,
												GroupLayout.PREFERRED_SIZE,
												115, GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(btnInvaddAddnew)
										.addContainerGap(37, Short.MAX_VALUE))
						.addComponent(jScrollPane1,
								GroupLayout.Alignment.TRAILING));
		pn_invadd_invoicedetailLayout
				.setVerticalGroup(pn_invadd_invoicedetailLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_invadd_invoicedetailLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pn_invadd_invoicedetailLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																lblInvaddProductid)
														.addComponent(
																lblInvaddQuantity)
														.addComponent(
																txtInvaddQuantity,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lblInvaddTotal)
														.addComponent(
																txtInvaddPrice,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnInvaddAddnew,
																GroupLayout.PREFERRED_SIZE,
																22,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cbbInvadd,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED,
												17, Short.MAX_VALUE)
										.addComponent(jScrollPane1,
												GroupLayout.PREFERRED_SIZE,
												259, GroupLayout.PREFERRED_SIZE)));
		txtInvaddQuantity.addKeyListener(controller);
		txtInvaddPrice.setEnabled(false);
		
		btnInvaddAdd.setFont(new java.awt.Font("Calibri", 1, 15));
		btnInvaddAdd.setIcon(new ImageIcon("icon/add.png"));
		btnInvaddAdd.setText("Add");
		btnInvaddAdd.setToolTipText("");
		btnInvaddAdd.addActionListener(controller);
		
		cbbInvadd.addActionListener(controller);
		
		btnInvaddCancel.setFont(new java.awt.Font("Calibri", 1, 15));
		btnInvaddCancel.setIcon(new ImageIcon("icon/clear.png"));
		btnInvaddCancel.setText("Clear");
		btnInvaddCancel.addActionListener(controller);

		GroupLayout layout = new GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(
						GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.TRAILING)
												.addComponent(
														pnInvaddInvoicedetail,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														pnInvaddInformation,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))
								.addContainerGap())
				.addGroup(
						layout.createSequentialGroup()
								.addGap(323, 323, 323)
								.addComponent(btnInvaddAdd,
										GroupLayout.PREFERRED_SIZE, 90,
										GroupLayout.PREFERRED_SIZE)
								.addGap(18, 18, 18)
								.addComponent(btnInvaddCancel,
										GroupLayout.PREFERRED_SIZE, 93,
										GroupLayout.PREFERRED_SIZE)
								.addContainerGap(GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(pnInvaddInformation,
										GroupLayout.PREFERRED_SIZE,
										GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(pnInvaddInvoicedetail,
										GroupLayout.PREFERRED_SIZE,
										GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.BASELINE)
												.addComponent(
														btnInvaddAdd,
														GroupLayout.PREFERRED_SIZE,
														30,
														GroupLayout.PREFERRED_SIZE)
												.addComponent(
														btnInvaddCancel,
														GroupLayout.PREFERRED_SIZE,
														30,
														GroupLayout.PREFERRED_SIZE))
								.addContainerGap(19, Short.MAX_VALUE)));
	}

	private void txt_invadd_invoiceidActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_txt_invadd_invoiceidActionPerformed
	}

	public JComboBox<String> getCbbInvadd() {
		
		return cbbInvadd;
	}
	
	private void events(){
		txtInvCustomerId.addKeyListener(controller);
	}

}
